import kivy
from kivy.app import App

from kivy.uix.button import Button, Label
from kivy.uix.scatter import Scatter
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse, Line

"""
初始化解决方案
https://blog.csdn.net/z564359805/article/details/92782079
"""
# 引入中文字体 默认字体无法显示中文
import os
# 引入资源目录,如res目录位于项目根目录下，写相对路径(不要写绝对路径)相当于告诉kivy　DroidSansFallback.ttf 字体位于res目录中
from kivy.resources import resource_add_path, resource_find

resource_add_path(os.path.abspath('./data/fonts'))
# 替换kivy中的默认字体，使用我们的新字体
from kivy.core.text import LabelBase

LabelBase.register('Roboto', 'DroidSansFallback.ttf')
# 可以要求最低的kivy版本
kivy.require('1.0.1')


class MyPaintWidget(Widget):
    def on_touch_down(self, touch):
        with self.canvas:
            Color(1, 1, 0)
            d = 30.
            Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
            touch.ud['line'] = Line(points=(touch.x, touch.y))

    def on_touch_move(self, touch):
        touch.ud['line'].points += [touch.x, touch.y]


class TestApp(App):

    # def build(self):
    #     # return Label(text="中文",font_name="font.TTF")
    #     # RGBA 颜色的四个分量
    #     # return Button(text='iPaoMi', background_color=(0, 0, 1, 1), font_size=150)
    #     s = Scatter()
    #     l = Label(text='iPaoMi', font_size=150)
    #     s.add_widget(l)
    #     return s

    def build(self):
        return MyPaintWidget()


TestApp().run()
